﻿
using Hx.ADSyncPlatform.InfrastructureSecurity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UtilForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public Dictionary<string, Func<string, string, string>> EncryptionMap = new Dictionary<string, Func<string, string, string>>();
        public Dictionary<string, Func<string, string, string>> DecryptionMap = new Dictionary<string, Func<string, string, string>>();
   
        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.cbxEncryptType.Text = this.cbxEncryptType.Items[0].ToString();
            this.EncryptionMap.Add("AES", Encrypt.AESEncrypt);
            this.DecryptionMap.Add("AES", Encrypt.AESDecrypt);
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncypt_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.rtxRaw.Text))
            {
                MessageBox.Show("原始文本不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(this.txtKey.Text))
            {
                MessageBox.Show("密钥不能为空！");
                return;
            }
            string encyptedText = this.EncryptionMap[this.cbxEncryptType.Text](this.rtxRaw.Text,this.txtKey.Text);
            this.rtxEncypted.Text = encyptedText;
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.rtxEncypted.Text))
            {
                MessageBox.Show("加密后的文本不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(this.txtKey.Text))
            {
                MessageBox.Show("密钥不能为空！");
                return;
            }
            string decyptedText = this.DecryptionMap[this.cbxEncryptType.Text](this.rtxEncypted.Text, this.txtKey.Text);
            this.rtxRaw.Text = decyptedText;
        }

    }
}
